package com.example.reactor;

import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;

@Slf4j
public class Practice2 {

    public static void main(String[] args) {

        List<Long> list = new ArrayList<>();
        list.add(1L);
        list.add(2L);
        list.add(3L);

        String initial = "123";
        Flux.fromIterable(list).reduce(initial, new BiFunction<String, Long, String>() {
            @Override
            public String apply(String s, Long aLong) {
                String result = s + String.valueOf(aLong);
                log.info(result);
                return result;
            }
        }).subscribe(
                i -> {
                    log.info("执行结束");
                    log.info(i);
                }
        );


        System.out.println("---------------------------------------分割线-------------------------------------");


        Map<String, List<Integer>> map = new HashMap<>();
        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        list1.add(2);
        list1.add(3);

        map.put("qwer", list1);

        Flux.fromIterable(map.get("qwer")).map(i -> {
            i = i + 1;
            return i;
        }).subscribe();

        log.info("map = {}", map);

    }

}
